package cn.wolfcode.car.business.service.impl;

import cn.wolfcode.car.business.domain.CustomerLinkMane;
import cn.wolfcode.car.business.mapper.CustomerMapper;
import cn.wolfcode.car.business.domain.Customer;
import cn.wolfcode.car.business.query.CustomerQuery;
import cn.wolfcode.car.business.service.ICustomerService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.base.query.QueryObject;
import cn.wolfcode.car.shiro.ShiroUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;


    @Override
    public TablePageInfo<Customer> query(CustomerQuery query) {
        //使用paigeHelper插件
        PageHelper.startPage(query.getPageNum(),query.getPageSize());
        //将list集合传入到TablePageInfo进行封装
        return new TablePageInfo<Customer>(customerMapper.selectForList(query));
    }



    @Override
    public void save(Customer customer) {
        Long id = ShiroUtils.getUser().getId();
        customer.setInputUser(id);
        customer.setInputTime(new Date());
        customerMapper.insert(customer);
    }

    @Override
    public void edit(Customer customer) {
        customerMapper.updateByPrimaryKey(customer);
    }

    @Override
    public Customer get(Long id) {
        return customerMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Customer> selectAll() {
        return customerMapper.selectAll();
    }


}
